$(function () {
    selectHeadFoot();
})

function selectHeadFoot() {
    $.ajax({
        url:'/back/mainPage/selectHeadFoot',
        data:'',
        dataType:'json',
        type:'get',
        success:function (data) {
            data = data.model;
            let html='';
            html+='<tr>\n' +
                '            <td>'+data.id+'</td>\n' +
                '            <td>'+data.title+'</td>\n' +
                '            <td>'+data.englishtitle+'</td>\n' +
                '            <td><img src="/back/img'+data.photo+'" width="150px"/></td>\n' +
                '            <td>'+data.foothref+'</td>\n' +
                '            <td>'+data.footwords+'</td>\n' +
                '            <td><a href="javascript:edit()">编辑</a>&nbsp;' +
                '            </td>\n' +
                '        </tr>';
            $("#findHeadFoot").html(html);
        }
    });

}
function edit() {
    $.ajax({
        url:'/back/mainPage/selectHeadFoot',
        data:'',
        dataType:'json',
        type:'get',
        success:function (data) {
            data = data.model;
            let html='';
            html+='<div>系统名称：<input id="title" type="text" value='+data.title+'></div>\n' +
                '    <div>英 文 名：<textarea id="englishtitle">'+data.englishtitle+'</textarea></div>\n' +
                '    <div>图  片：<input id="photo" type="file" onclick="hide()" value='+data.photo+'/></div>\n' +
                '    <div><img id="img" src="/back/img'+data.photo+'" width="120px" style="margin-left: 52px"/></div>\n' +
                '    <div>尾部链接：<input id="foothref" type="text" value='+data.foothref+'></div>\n' +
                '    <div>尾部文字：<textarea id="footwords" style="height: 70px">'+data.footwords+'</textarea></div>\n' +
                '    <div><button onclick="updateHeadFoot()">确定修改</button></div>';
            $("#editHeadFoot").html(html);
        }
    })
}
function hide() {
    $("#img").attr("src","");
}
//更新HeadandFoot的信息
function updateHeadFoot() {
    let data = new FormData();
    data.append("title",$("#title").val());
    data.append("englishtitle",$("#englishtitle").val());
    data.append("photo",$("#photo")[0].files[0]);
    data.append("foothref",$("#foothref").val());
    data.append("footwords",$("#footwords").val());
    console.log(data);
    $.ajax({
        url:'/back/mainPage/updateHeadFoot',
        data:data,
        dataType:'json',
        type:'post',
        contentType:false ,
        processData: false,
        success:function (data) {
            console.log(data)
            if (data==1){
                alert("更新成功");
            }else {
                alert("更新失败");
            }
        }
    })
}